package com.violet.myorm.core.sql;

import java.util.List;

public class InsertSql extends Sql {

    public InsertSql(String tableName, List<String> fields) {
        sql.append("INSERT INTO ").append(tableName).append(" (");
        for (int i = 0; i < fields.size(); i++) {
            sql.append(fields.get(i));
            if (i < fields.size() - 1) {
                sql.append(",");
            }
        }
        sql.append(") VALUES ");
    }

    public void insert(int fieldSize, int size) {
        if (sql.charAt(sql.length() - 1) == ')') sql.append(", ");
        while ((size -= fieldSize) >= 0) {
            sql.append("(");
            sql.append("?,".repeat(Math.max(0, fieldSize)));
            sql.deleteCharAt(sql.length() - 1);
            sql.append("), ");
        }
        sql.deleteCharAt(sql.length() - 2);
    }

}
